import Vue from "vue";
import Vuex from "vuex";
import VueRouter from "vue-router";
import vueStore from "./store.js";
import routes from "./routes";
import App from "./app.vue";
import VueI18n from 'vue-i18n';
import Lang from "i18n/lang.js";
import '@/api/interceptors';
import iView from 'iview';
import 'iview/dist/styles/iview.css';
import "./main.scss";
import "@/scss/flexbox.scss";
import "@/scss/ivureset.scss";
import VueSocketio from 'vue-socket.io';
// Vue.use(VueSocketio, 'ws://192.168.35.204:9100');
import VTooltip from 'v-tooltip'
import VueContextMenu from 'vue-contextmenu'
import VModal from 'vue-js-modal' //modal组件

Vue.use(VueI18n);
Vue.use(VueRouter);
Vue.use(Vuex);
Vue.use(iView);
Vue.use(VTooltip);
Vue.use(VueContextMenu);
Vue.use(VModal,{ dynamic: true ,injectModalsContainer: true});

// 加载vuex store
const store = new Vuex.Store(vueStore);

// 配置路由
const router = new VueRouter({
    routes,
    //模拟浏览器返回顶部行为
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) { //通过返回按钮返回
            return savedPosition;
        } else {
            return {
                x: 0,
                y: 0
            };
        }
    }
});

// 国际化
// 将默认语言保存到localStorage中
const i18n = new VueI18n({
    locale: Lang.getLocale(),
    messages: Lang
})

const whiteList = ['login', 'notFound'];//页面控制白名单

router.beforeEach((to, from, next) => {
    if (whiteList.indexOf(to.name) >= 0) {
        next();
    } else {

    }
    // document.title = `${ i18n.t("common.M001") }|${ i18n.t(to.meta.title) }`;
    next();
})

const app = new Vue({
    components: { App },
    store,
    router,
    i18n
}).$mount("#app");